{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 期望 np.mean()  方差 np.var 标准差(均方差)  np.std()\n",
    "import numpy as np\n",
    "\n",
    "# 使用np.random.standard_normal() 随机生成200只股票 504个交易日符合正态分布的涨跌幅数据\n",
    "# 504=252*2 两年美股交易日总数 \n",
    "# 正态分布 即为高斯分布\n",
    "\n",
    "stock_cnt = 200\n",
    "view_days = 504\n",
    "# 生成符合正态分布均值期望为0， 标准差为1\n",
    "stock_day_change = np.random.standard_normal((stock_cnt, view_days))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 切片\n",
    "stock_day_change_four = stock_day_change[:4, :4] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2.11891034, 0.2935652 , 1.40259311, 0.43366887])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 统计信息\n",
    "# 横向的统计某只股票4天内的信息，需要使用参数 axis = 1\n",
    "# 纵向的统计 axis = 0\n",
    "\n",
    "# 横向4天内最大涨幅 无法锁定哪一天\n",
    "np.max(stock_day_change_four, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-0.33251486, -0.23216331, -1.69712973, -1.69002258])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 横向4天内最大跌幅\n",
    "np.min(stock_day_change_four, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.92981209, 0.20159383, 1.23722099, 0.82619443])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 振幅幅度\n",
    "np.std(stock_day_change_four, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.69419164, -0.04427064,  0.24271534, -0.28526078])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 平均涨幅\n",
    "np.mean(stock_day_change_four, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 0, 3])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取哪一天的涨幅最大\n",
    "np.argmax(stock_day_change_four, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 3, 3, 2])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取哪一天跌幅最大\n",
    "np.argmin(stock_day_change_four, axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Python 的 max()  min() 和 np.max() np.min()  函数的作用时相同的，在数据量非常小的情况下使用Numpy库执行的效率反而低下，类似的还有round()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
